package com.token.controller;

import com.token.common.ResultMessage;
import com.token.model.dto.BindingDTO;
import com.token.utils.ParamHandleUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @auther: henriy
 * @Date: 2024/1/2
 */
@RestController
@RequestMapping("/test")
public class BindingController {

    @PostMapping(value = "/binding")
    public ResultMessage testBinding(@Valid @RequestBody BindingDTO bindingDTO, BindingResult bindingResult) {

        if (bindingResult.hasErrors()) {
            String validResult = ParamHandleUtils.handleParam(bindingResult.getAllErrors());
            return ResultMessage.errMsg(validResult);
        }

        return ResultMessage.isOk();
    }

}
